<template>
    <div class="account-container">
        <div class="account-sidebar">
            <div class="user-info">
                <div class="avatar">
                    <img :src="userInfo.avatar" :alt="$t('Account.Index.Avatar')" @error="handleAvatarError" />
                </div>
                <div class="user-details">
                    <h3>{{ userInfo.nickname }}</h3>
                    <p>{{ userInfo.email }}</p>
                </div>
            </div>
            <div class="menu-list">
                <router-link v-for="item in menuItems" :key="item.path" :to="item.path" :class="['menu-item', { active: route.path === item.path }]">
                    <img :src="item.icon" :alt="item.name" />
                    {{ item.name }}
                </router-link>
            </div>
        </div>
        <div class="account-content">
            <router-view></router-view>
        </div>
    </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import zhanghu from '@/assets/header/zhanghu.png'
import taocan from '@/assets/header/taocan.png'
import defaultAvatar from '@/assets/header/user.png'
import encrypt from '@/utils/encrypt.js'

const route = useRoute()
const { t } = useI18n()
// const username = ref('feifan fu')
// const email = ref('fufeifan@gmail.com')
const userInfo = encrypt.GetLocalData('userInfo')
const menuItems = [
    {
        name: t('Account.Index.MyAccount'),
        path: '/account/profile',
        icon: zhanghu
    },
    {
        name: t('Account.Index.MySubscription'),
        path: '/account/subscription',
        icon: taocan
    }
]

const handleAvatarError = (event) => {
    event.target.src = defaultAvatar
}
</script>

<style lang="scss" scoped>
.account-container {
    display: flex;
    height: calc(100% - 2px);
    background: #f5f7fa;
    color: #333;
    margin-top: 2px;
}

.account-sidebar {
    width: 280px;
    background: white;
    padding: 24px;
    border-right: 1px solid #eee;

    .user-info {
        display: flex;
        align-items: center;
        padding: 20px 0;
        border-bottom: 1px solid #eee;
        margin-bottom: 20px;

        .avatar {
            width: 48px;
            height: 48px;
            background: #1a73e8;
            color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            margin-right: 12px;

            img{
                width: 100%;
                height: 100%;
                border-radius: 50%;
            }
        }

        .user-details {
            h3 {
                font-size: 16px;
                margin-bottom: 4px;
            }

            p {
                color: #666;
                font-size: 14px;
            }
        }
    }

    .menu-list {
        .menu-item {
            display: flex;
            align-items: center;
            padding: 12px 16px;
            color: #333;
            text-decoration: none;
            border-radius: 8px;
            margin-bottom: 8px;
            transition: all 0.3s;

            img {
                width: 20px;
                height: 20px;
                margin-right: 12px;
            }

            &:hover {
                background: #f5f7fa;
            }

            &.active {
                background: #e8f0fe;
                color: #1a73e8;
            }
        }
    }
}

.account-content {
    flex: 1;
    padding: 32px;
}
</style>
